package com.DongBing.controller;

import java.util.List;

import ch.qos.logback.core.pattern.util.RegularEscapeUtil;
import com.DongBing.common.utils.Res;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import com.DongBing.entity.CategoryEntity;
import com.DongBing.service.CategoryService;



/**
 * 商品三级分类
 *
 * @author ¶­±ù
 * @email 861571118@QQ.com
 * @date 2022-05-16 15:56:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/product/category")
public class CategoryController {

    private final CategoryService categoryService;

    /**
     * 展示树形菜单
     * @return res
     */
    @GetMapping(value = "/list/tree")
    public Res<List<CategoryEntity>> listTree(){
        return categoryService.listTree();
    }

    /**
     * 删除分类
     * @param ids 主键
     * @return res
     */
    @GetMapping(value = "/delete/{ids}")
    public Res<?> delete(@PathVariable("ids") String ids){
        return categoryService.delete(ids);
    }

    /**
     * 批量删除
     * @param ids 批量删的主键id
     * @return res
     */
    @PostMapping(value = "/deletes")
    public Res<?> deletes(@RequestBody Long[] ids){
        return categoryService.deletes(ids);
    }

    /**
     * 添加分类
     * @param categoryEntity 数据
     * @return res
     */
    @PostMapping(value = "/insert")
    public Res<?> insert(@RequestBody CategoryEntity categoryEntity){
        return categoryService.insert(categoryEntity);
    }

    /**
     * 修改type
     * @param categoryEntity 数据
     * @return res
     */
    @PostMapping(value = "/update")
    public Res<?> update(@RequestBody CategoryEntity categoryEntity){
        return categoryService.update(categoryEntity);
    }
}
